<?php
namespace Api\Model;
use Think\Model;

class CommonModel extends Model{
	public $autoCheckFields = false;
	
	/**
	 * 获取记录字段值
	 * @param  string $model [description]
	 * @param  [type] $id    [description]
	 * @return [type]        [description]
	 */
	public function get_field_val($model = 'Link', $id = '', $field='title'){
		$where['id'] = $id;
		$val = D($model)->where($where)->getField($field);
		return $val ? $val : '';
	}
	public function get_short_link_url($id){
		if(!$id){
			return '';
		}

		$path = C('SHORT_LINK_DOMAIN');

		$where['id'] = $id;
		$short_key = D('Link')->where($where)->getField('short_key');
		$short_url = ($path ? $path . '/' : '') . $short_key;
		return $short_url;;
	}
	/**
	 * 获取配置项值
	 * @param  [type] $name       KEY
	 * @param  [type] $type       类型
	 */
	public function get_config_val($name,$type='system'){
		$where['name'] = $name;
		$where['type'] = $type;
		return D('Config')->where($where)->getField('val');
	}
}